package offer;

/**
 * @Author SSK
 * @Date Created in 19:16 2019/8/4
 * @Description 孩子们的游戏(圆圈中最后剩下的数)
 * @Version 1.0
 */
public class T47 {
    public int LastRemaining_Solution(int n, int m) {
        if (m<=0) return -1;
        if (m==1) {
            return n-1;
        }
        int ans = 0;
        for (int i = 2; i <= n; i++) {
            ans = (ans + m )%i;
        }
        return ans;
    }
}
